import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import postcssNested from 'postcss-nested'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'

export default defineConfig({
  server: {
    proxy: {
      '/food': { target: 'http://localhost:8080', changeOrigin: true },
      '/user': { target: 'http://localhost:8080', changeOrigin: true },
      '/data': { target: 'http://localhost:8080', changeOrigin: true },
      '/restaurant': { target: 'http://localhost:8080', changeOrigin: true },
      '/manage': { target: 'http://localhost:8080', changeOrigin: true },
      '/order': { target: 'http://localhost:8080', changeOrigin: true },
      '/review': { target: 'http://localhost:8080', changeOrigin: true },
      '/complain': { target: 'http://localhost:8080', changeOrigin: true },
      '/bili': { target: 'http://localhost:8080', changeOrigin: true }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue'],
      resolvers: [ElementPlusResolver(), IconsResolver()],
      eslintrc: { enabled: true }
    }),
    Components({
      resolvers: [ElementPlusResolver(), IconsResolver({ enabledCollections: ['ep'] })]
    }),
    Icons({ autoInstall: true })
  ],
  css: {
    postcss: './postcss.config.js' // 确保指向正确的配置文件
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
